<?php 
 include_once dirname(__FILE__)."/config.php";
 class unite_email_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_id;
		 protected $_id_unite;
		 protected $_id_mail;
		 protected $_id_config_envoi;
		 protected $_phase;
		 protected $_envoyer;
		 protected $_erreur;
		 protected $_mail;
		 protected $_email;
		 protected $_personne;
		 protected $_sujet;
		 public function get_name_table(){ return "unite_email";}
		 public function get_name_id(){ return "id";}
		 public function get_name_id_unite(){ return "id_unite";}
		 public function get_name_id_mail(){ return "id_mail";}
		 public function get_name_id_config_envoi(){ return "id_config_envoi";}
		 public function get_name_phase(){ return "phase";}
		 public function get_name_envoyer(){ return "envoyer";}
		 public function get_name_erreur(){ return "erreur";}
		 public function get_name_mail(){ return "mail";}
		 public function get_name_email(){ return "email";}
		 public function get_name_personne(){ return "personne";}
		 public function get_name_sujet(){ return "sujet";}
		 public function set_id($parametre){  $this->_id=$parametre;}	
		 public function set_id_unite($parametre){  $this->_id_unite=$parametre;}	
		 public function set_id_mail($parametre){  $this->_id_mail=$parametre;}	
		 public function set_id_config_envoi($parametre){  $this->_id_config_envoi=$parametre;}	
		 public function set_phase($parametre){  $this->_phase=$parametre;}	
		 public function set_envoyer($parametre){  $this->_envoyer=$parametre;}	
		 public function set_erreur($parametre){  $this->_erreur=$parametre;}	
		 public function set_mail($parametre){  $this->_mail=$parametre;}	
		 public function set_email($parametre){  $this->_email=$parametre;}	
		 public function set_personne($parametre){  $this->_personne=$parametre;}	
		 public function set_sujet($parametre){  $this->_sujet=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id(){ return $this->_id;}
		 public function get_id_unite(){ return $this->_id_unite;}
		 public function get_id_mail(){ return $this->_id_mail;}
		 public function get_id_config_envoi(){ return $this->_id_config_envoi;}
		 public function get_phase(){ return $this->_phase;}
		 public function get_envoyer(){ return $this->_envoyer;}
		 public function get_erreur(){ return $this->_erreur;}
		 public function get_mail(){ return $this->_mail;}
		 public function get_email(){ return $this->_email;}
		 public function get_personne(){ return $this->_personne;}
		 public function get_sujet(){ return $this->_sujet;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 unite_email(
			id_unite,
			id_mail,
			id_config_envoi,
			phase,
			envoyer,
			erreur,
			mail,
			email,
			personne,
			sujet)
 VALUES(
			'".$this->_id_unite."',
			'".$this->_id_mail."',
			'".$this->_id_config_envoi."',
			'".$this->_phase."',
			'".$this->_envoyer."',
			'".$this->_erreur."',
			'".$this->_mail."',
			'".$this->_email."',
			'".$this->_personne."',
			'".$this->_sujet."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_id_unite)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_unite='".$this->_id_unite."'";
}
if(!empty($this->_id_mail)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_mail='".$this->_id_mail."'";
}
if(!empty($this->_id_config_envoi)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_config_envoi='".$this->_id_config_envoi."'";
}
if(!empty($this->_phase)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
phase='".$this->_phase."'";
}
if(!empty($this->_envoyer)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
envoyer='".$this->_envoyer."'";
}
if(!empty($this->_erreur)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
erreur='".$this->_erreur."'";
}
if(!empty($this->_mail)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
mail='".$this->_mail."'";
}
if(!empty($this->_email)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
email='".$this->_email."'";
}
if(!empty($this->_personne)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
personne='".$this->_personne."'";
}
if(!empty($this->_sujet)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
sujet='".$this->_sujet."'";
}
$sql="UPDATE 
unite_email SET 
 ".$sql."
								WHERE id ='".$this->_id."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
unite_email 
 
									WHERE id ='".$this->_id."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
unite_email ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id,
		id_unite,
		id_mail,
		id_config_envoi,
		phase,
		envoyer,
		erreur,
		mail,
		email,
		personne,
		sujet
 FROM 
 unite_email";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id=$row->id;
		$this->_id_unite=$row->id_unite;
		$this->_id_mail=$row->id_mail;
		$this->_id_config_envoi=$row->id_config_envoi;
		$this->_phase=$row->phase;
		$this->_envoyer=$row->envoyer;
		$this->_erreur=$row->erreur;
		$this->_mail=$row->mail;
		$this->_email=$row->email;
		$this->_personne=$row->personne;
		$this->_sujet=$row->sujet;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>